import Cookies from 'js-cookie'
// import dSettings from '@/settings'
const cookie_token = 'SHN_Token'
const cookie_tokenTime = 'SHN_TokenTime'
const cookie_domain = 'trxnyyun.com'
const applicationType = 'Web'
const languageType = 'zh-cn'

export function token_get() {
  const tokenTime = Cookies.get(cookie_tokenTime)
  if (tokenTime) {
    const nowTime = new Date().getTime()
    if (nowTime < tokenTime) {
      return Cookies.get(cookie_token)
    }
  }
  token_del()
  return null
}
export function token_set(token) {
  const tokenDomain = token_domain()
  Cookies.set(cookie_token, token, { path: '/', domain: tokenDomain })
  const tokenTime = new Date(new Date().getTime() + 20 * 60 * 1000)
  Cookies.set(cookie_tokenTime, tokenTime.getTime(), { path: '/', domain: tokenDomain })
}
export function token_del() {
  const tokenDomain = token_domain()
  Cookies.remove(cookie_token, { path: '/', domain: tokenDomain })
  Cookies.remove(cookie_tokenTime, { path: '/', domain: tokenDomain })
}
export function applicationType_get() {
  return applicationType
}
export function languageType_get() {
  return languageType
}
export function token_domain() {
  const name = window.location.hostname
  if (
    name.indexOf('.trxnyyun.com') > 0 ||
    name.indexOf('.trenergycloud.com') > 0 ||
    name.indexOf('.towngastree.com') > 0
  ) {
    return cookie_domain
  } else {
    return null
  }
}
